package com.xjscrm.console.service.customer.group.impl;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.github.pagehelper.PageHelper;
import com.uzai.mobile.collect.api.MicaTopics;
import com.uzai.mobile.collect.api.dto.MicaTriggerDto;
import com.uzai.mobile.collect.api.dto.trigger.group.MicaTriggerGroupKickMsg;
import com.uzai.mobile.collect.api.enums.MicaTriggerType;
import com.xjscrm.common.constant.ResponseMsg;
import com.xjscrm.common.entity.*;
import com.xjscrm.common.enums.DeviceTypeEnum;
import com.xjscrm.common.enums.RedisCacheKeyEnum;
import com.xjscrm.common.exception.BusinessException;
import com.xjscrm.common.result.ResponseCode;
import com.xjscrm.common.utils.DateUtil;
import com.xjscrm.common.utils.OrderByUtil;
import com.xjscrm.console.mapper.*;
import com.xjscrm.console.mq.producer.SendMsgProducer;
import com.xjscrm.console.param.BaseDto;
import com.xjscrm.console.param.group.*;
import com.xjscrm.console.param.list.WwCustomerListQuery;
import com.xjscrm.console.service.customer.group.WwGroupMemberDistinctService;
import com.xjscrm.console.vo.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service
public class WwGroupMemberDistinctServiceImpl implements WwGroupMemberDistinctService {

    @Autowired
    private WwGroupMapper wwGroupMapper;

    @Autowired
    private WwGroupMemberMapper wwGroupMemberMapper;

    @Autowired
    private RepeatWwGroupMerberMapper repeatWwGroupMerberMapper;

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private RepeatWwGroupMemberLogMapper repeatWwGroupMemberLogMapper;

    @Autowired
    private WwDeviceMapper wwDeviceMapper;

    @Autowired
    private SendMsgProducer sendMsgProducer;

    @Autowired
    private WhiteListMapper whiteListMapper;

    @Override
    @Async("taskExecutor")
    public void checkRepeatMember(CheckRepeatMemberDto checkRepeatMemberDto) {
        if (checkRepeatMemberDto.getMerId() == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        if (checkRepeatMemberDto.getWwGroupIds() == null && checkRepeatMemberDto.getWwGroupIds().isEmpty()) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        if (checkRepeatMemberDto.getWwGroupIds().size() < 2 || checkRepeatMemberDto.getWwGroupIds().size() > 30) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }

        //删除上次的检测标识
        String redisKey = String.format(RedisCacheKeyEnum.DISTINCT_GROUP_MEMBER_WHICH_FALG.getKey(), checkRepeatMemberDto.getMerId());
        if (redisTemplate.hasKey(redisKey)) {
            redisTemplate.delete(redisKey);
        }

        Long falg = IdWorker.getId();
        //设置取消标识
        String key = String.format(RedisCacheKeyEnum.DISTINCT_GROUP_MEMBER_BREAK_FALG.getKey(), checkRepeatMemberDto.getMerId());
        redisTemplate.opsForValue().set(key, falg);

        Map<String, List<Long>> map = new HashMap<>();
        for (Long id : checkRepeatMemberDto.getWwGroupIds()) {
            WwGroup wwGroup = wwGroupMapper.getById(id, checkRepeatMemberDto.getMerId());
            if (wwGroup == null || wwGroup.getGroupWxid() == null) {
                continue;
            }
            WwGroupMemberQuery wwGroupMemberQuery = new WwGroupMemberQuery();
            wwGroupMemberQuery.setMerId(wwGroup.getMerId());
            wwGroupMemberQuery.setGroupWxid(wwGroup.getGroupWxid());
            List<WwGroupMemberVo> wwGroupMemberList = wwGroupMemberMapper.getWwGroupMemberList(wwGroupMemberQuery);
            if (wwGroupMemberList == null || wwGroupMemberList.isEmpty()) {
                continue;
            }

            for (WwGroupMemberVo wwGroupMemberVo : wwGroupMemberList) {
                //暂停，删除该key 终止任务
                if (!redisTemplate.hasKey(key)) {
                    return;
                }

                // 检测是否是企业号   查询是否要忽略白名单 要则在白名单中忽略
                if(checkRepeatMemberDto.getIgnoreWhiteList()!=null&&checkRepeatMemberDto.getIgnoreWhiteList()==1){
                    if(!StringUtils.isBlank(wwGroupMemberVo.getCorpId())){
                        continue;
                    }

                    WwCustomerListQuery wwCustomerListQuery=new WwCustomerListQuery();
                    wwCustomerListQuery.setMerId(checkRepeatMemberDto.getMerId());
                    wwCustomerListQuery.setWxid(wwGroupMemberVo.getWxid());
                    List<WwCustomerWhiteVo> whiteList = whiteListMapper.getWhiteList(wwCustomerListQuery);
                    if(whiteList!=null&&!whiteList.isEmpty()){
                        continue;
                    }
                }

                boolean keyExists = map.containsKey(wwGroupMemberVo.getWxid());
                if (!keyExists) {
                    map.put(wwGroupMemberVo.getWxid(), Arrays.asList(wwGroup.getId()));
                } else {
                    List<Long> groupIds = new ArrayList<>(map.get(wwGroupMemberVo.getWxid()));
                    groupIds.add(wwGroup.getId());
                    map.put(wwGroupMemberVo.getWxid(), groupIds);
                }
            }
        }

        if (!map.isEmpty()) {
            for (Map.Entry<String, List<Long>> entry : map.entrySet()) {
                List<Long> groupIds = entry.getValue();
                if (groupIds != null && groupIds.size() >= 2) {
                    try {
                        addRepeatWwGroupMember(checkRepeatMemberDto, entry, falg);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }

            }
        }
        //插入去重记录
        addRepeatWwGroupMemberLog(checkRepeatMemberDto, falg);

        //去重标识放入缓存
        String redisCacheKey = String.format(RedisCacheKeyEnum.DISTINCT_GROUP_MEMBER_WHICH_FALG.getKey(), checkRepeatMemberDto.getMerId());
        redisTemplate.opsForValue().set(redisCacheKey, falg);
    }


    private void addRepeatWwGroupMember(CheckRepeatMemberDto checkRepeatMemberDto, Map.Entry<String, List<Long>> entry, Long falg) {
        //获取群成员
        String groupMerberWxid = entry.getKey();
        List<Long> groupIds = entry.getValue();
        WwGroupMemberQuery wwGroupMemberQuery=new WwGroupMemberQuery();
        wwGroupMemberQuery.setMerId(checkRepeatMemberDto.getMerId());
        wwGroupMemberQuery.setWxid(groupMerberWxid);
        List<WwGroupMemberVo> wwGroupMemberList = wwGroupMemberMapper.getWwGroupMemberList(wwGroupMemberQuery);
        if (wwGroupMemberList == null||wwGroupMemberList.isEmpty()) {
            return;
        }
        WwGroupMemberVo wwGroupMemberVo = wwGroupMemberList.get(0);
        RepeatWwGroupMerber repeatWwGroupMerber = new RepeatWwGroupMerber();
        repeatWwGroupMerber.setMerId(checkRepeatMemberDto.getMerId());
        repeatWwGroupMerber.setWxid(wwGroupMemberVo.getWxid());
        repeatWwGroupMerber.setNick(wwGroupMemberVo.getNick());
        repeatWwGroupMerber.setHimg(wwGroupMemberVo.getHimg());
        repeatWwGroupMerber.setStatus(0);
        repeatWwGroupMerber.setFalg(falg);

        //获取群
        WwGroupQuery wwGroupQuery = new WwGroupQuery();
        wwGroupQuery.setIds(groupIds);
        wwGroupQuery.setMerId(checkRepeatMemberDto.getMerId());
        List<WwGroupVo> wwGroupList = wwGroupMapper.getWwGroupList(wwGroupQuery);
        if (wwGroupList == null || wwGroupList.isEmpty()) {
            return;
        }
        List<GroupData> groupDataList = new ArrayList<>();
        wwGroupList.forEach(it -> {
            GroupData groupData = new GroupData();
            groupData.setId(it.getId());
            groupData.setGroupWxid(it.getGroupWxid());
            groupData.setGroupName(it.getGroupName());
            groupData.setHeadImageUrl(it.getHeadImageUrl());
            groupData.setStatus(0);
            groupDataList.add(groupData);
        });
        repeatWwGroupMerber.setGroupData(JSONObject.toJSONString(groupDataList));
        repeatWwGroupMerberMapper.addRepeatWwGroupMerber(repeatWwGroupMerber);
    }

    private void addRepeatWwGroupMemberLog(CheckRepeatMemberDto checkRepeatMemberDto, Long falg) {
        int time = DateUtil.getTime();
        RepeatWwGroupMemberLog repeatWwGroupMemberLog = new RepeatWwGroupMemberLog();
        repeatWwGroupMemberLog.setId(falg);
        repeatWwGroupMemberLog.setMerId(checkRepeatMemberDto.getMerId());
        if (checkRepeatMemberDto.getOperatorType() == 0) {
            repeatWwGroupMemberLog.setUserId(checkRepeatMemberDto.getMerId());
            repeatWwGroupMemberLog.setOperateType(0);
        }
        if (checkRepeatMemberDto.getOperatorType() == 1) {
            repeatWwGroupMemberLog.setUserId(checkRepeatMemberDto.getChildId());
            repeatWwGroupMemberLog.setOperateType(1);
        }
        repeatWwGroupMemberLog.setRepeatNum(0);

        Integer totalByFalg = repeatWwGroupMerberMapper.getTotalByFalg(falg, checkRepeatMemberDto.getMerId());
        repeatWwGroupMemberLog.setTotalNum(totalByFalg);
        repeatWwGroupMemberLog.setCreateTime(time);
        repeatWwGroupMemberLog.setUpdateTime(time);
        repeatWwGroupMemberLogMapper.insertRepeatWwGroupMemberLog(repeatWwGroupMemberLog);
    }


    @Override
    public Object getCheckStatus(BaseDto baseDto) {
        if (baseDto.getMerId() == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        String redisKey = String.format(RedisCacheKeyEnum.DISTINCT_GROUP_MEMBER_WHICH_FALG.getKey(), baseDto.getMerId());
        if (!redisTemplate.hasKey(redisKey)) {
            return false;
        }
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void breakCheck(BaseDto baseDto) {
        if (baseDto.getMerId() == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
       //设置取消标识
        String key = String.format(RedisCacheKeyEnum.DISTINCT_GROUP_MEMBER_BREAK_FALG.getKey(), baseDto.getMerId());
        if (redisTemplate.hasKey(key)) {
            Long falg = (Long) redisTemplate.opsForValue().get(key);

            //删除已经插入的去重群成员
            RepeatWwGroupMerberQuery repeatWwGroupMerberQuery=new RepeatWwGroupMerberQuery();
            repeatWwGroupMerberQuery.setMerId(baseDto.getMerId());
            repeatWwGroupMerberQuery.setFalg(falg);
            List<RepeatWwGroupMerberVo> repeatWwGroupMerberVoList= repeatWwGroupMerberMapper.getRepeatWwGroupMerber(repeatWwGroupMerberQuery);
            if(repeatWwGroupMerberVoList!=null&&!repeatWwGroupMerberVoList.isEmpty()){
                repeatWwGroupMerberVoList.forEach(it->repeatWwGroupMerberMapper.deleById(it.getId(),it.getMerId()));
            }

            //删除去重的日志
           RepeatWwGroupMemberLog repeatWwGroupMemberLog= repeatWwGroupMemberLogMapper.getById(falg,baseDto.getMerId());
           if(repeatWwGroupMemberLog!=null){
               repeatWwGroupMemberLogMapper.deleById(repeatWwGroupMemberLog.getId(),repeatWwGroupMemberLog.getMerId());
           }

           redisTemplate.delete(key);
        }
    }

    @Override
    public Object getCheckResult(RepeatWwGroupMerberQuery repeatWwGroupMerberQuery) {

        if(repeatWwGroupMerberQuery.getMerId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        String redisKey= String.format(RedisCacheKeyEnum.DISTINCT_GROUP_MEMBER_WHICH_FALG.getKey(),repeatWwGroupMerberQuery.getMerId());
        if(!redisTemplate.hasKey(redisKey)){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "检测记录缺失，请重新检测");
        }
        Long falg = (Long) redisTemplate.opsForValue().get(redisKey);
        repeatWwGroupMerberQuery.setFalg(falg);
        String orderBy = OrderByUtil.getOrderBy(repeatWwGroupMerberQuery.getOrderByField(), repeatWwGroupMerberQuery.isAsc());
        PageHelper.startPage(repeatWwGroupMerberQuery.getCurrent(),repeatWwGroupMerberQuery.getSize(),orderBy);
        List<RepeatWwGroupMerberVo> repeatWwGroupMerberVoList = repeatWwGroupMerberMapper.getRepeatWwGroupMerber(repeatWwGroupMerberQuery);
        if(repeatWwGroupMerberVoList!=null&&!repeatWwGroupMerberVoList.isEmpty()){
            for (RepeatWwGroupMerberVo repeatWwGroupMerberVo:repeatWwGroupMerberVoList) {
                try {
                    if(!StringUtils.isBlank(repeatWwGroupMerberVo.getGroupData())){
                        repeatWwGroupMerberVo.setGroupDataList(JSONArray.parseArray(repeatWwGroupMerberVo.getGroupData(),GroupData.class));
                    }

                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }

        return new MyPageInfo<>(repeatWwGroupMerberVoList);
    }


    @Override
    public Object deleRepeatMember(DeleRepeatMemberDto deleRepeatMemberDto) {
        if(deleRepeatMemberDto.getMerId()==null){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }

        Integer delNumber=0;
        String delRepeatMemberNumber=String.format(RedisCacheKeyEnum.DEL_REPEAT_GROUP_MEMBER_NUMBER.getKey(),deleRepeatMemberDto.getMerId());
        redisTemplate.opsForValue().set(delRepeatMemberNumber,0);

        if(deleRepeatMemberDto.getRepeatType()==0){
            deleRepeatGroupMemberAll(deleRepeatMemberDto);
        }
        if(deleRepeatMemberDto.getRepeatType()==1){
            deleRepeatGroupMemberBySelect(deleRepeatMemberDto);
        }
        delNumber= (Integer) redisTemplate.opsForValue().get(delRepeatMemberNumber);
        redisTemplate.delete(delRepeatMemberNumber);

        //插入去重日志
        String redisKey= String.format(RedisCacheKeyEnum.DISTINCT_GROUP_MEMBER_WHICH_FALG.getKey(),deleRepeatMemberDto.getMerId());
        if(redisTemplate.hasKey(redisKey)){
            Long falg = (Long) redisTemplate.opsForValue().get(redisKey);
            RepeatWwGroupMemberLog repeatWwGroupMemberLog = repeatWwGroupMemberLogMapper.getById(falg, deleRepeatMemberDto.getMerId());
            repeatWwGroupMemberLog.setRepeatNum(delNumber);
            repeatWwGroupMemberLogMapper.update(repeatWwGroupMemberLog);
        }
        return delNumber;
    }

    private void deleRepeatGroupMemberBySelect(DeleRepeatMemberDto deleRepeatMemberDto) {
        if(deleRepeatMemberDto.getKeepGroupDtoList()==null||deleRepeatMemberDto.getKeepGroupDtoList().isEmpty()){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }

        String redisKey= String.format(RedisCacheKeyEnum.DISTINCT_GROUP_MEMBER_WHICH_FALG.getKey(),deleRepeatMemberDto.getMerId());
        if(!redisTemplate.hasKey(redisKey)){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "检测记录缺失，请重新检测");
        }
        for (KeepGroupDto keepGroupDto:deleRepeatMemberDto.getKeepGroupDtoList()) {
            RepeatWwGroupMerber repeatWwGroupMerber= repeatWwGroupMerberMapper.getById(keepGroupDto.getId(),deleRepeatMemberDto.getMerId());
            if(repeatWwGroupMerber!=null&&!StringUtils.isBlank(repeatWwGroupMerber.getGroupData())){

                List<GroupData> groupDataList=JSONArray.parseArray(repeatWwGroupMerber.getGroupData(),GroupData.class);
                if(groupDataList!=null&&!groupDataList.isEmpty()){
                    List<GroupData> groupDatas=keepGroupMemberBySelect(groupDataList,repeatWwGroupMerber.getWxid(),repeatWwGroupMerber.getMerId(),deleRepeatMemberDto.getDeviceUniqueId(),keepGroupDto.getGroupIds());

                    if((groupDatas != null) && groupDatas.stream().anyMatch(it -> it.getStatus() == 1)) {
                        repeatWwGroupMerber.setStatus(1);
                    }
                    repeatWwGroupMerber.setGroupData(JSONObject.toJSONString(groupDatas));
                    repeatWwGroupMerberMapper.update(repeatWwGroupMerber);
                }
            }
        }
    }

    private List<GroupData> keepGroupMemberBySelect(List<GroupData> groupDataList, String wxid, Long merId, Long deviceUniqueId, List<Long> groupIds) {
        List<String> removedIdList = new ArrayList<>();
        for (GroupData groupData:groupDataList) {
            if(groupIds.contains(groupData.getId())){
                groupData.setStatus(0);
            }else {
                removedIdList.add(groupData.getGroupWxid());
                groupData.setStatus(1);
            }
        }

        //删除群成员
        deleGroupMember(removedIdList,wxid,merId,deviceUniqueId);

        return groupDataList;

    }

    private void deleRepeatGroupMemberAll(DeleRepeatMemberDto deleRepeatMemberDto) {

        String redisKey= String.format(RedisCacheKeyEnum.DISTINCT_GROUP_MEMBER_WHICH_FALG.getKey(),deleRepeatMemberDto.getMerId());
        if(!redisTemplate.hasKey(redisKey)){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "检测记录缺失，请重新检测");
        }
         //全量
        if(deleRepeatMemberDto.getKeepGroupDtoList()==null||deleRepeatMemberDto.getKeepGroupDtoList().isEmpty()){
            Long falg = (Long) redisTemplate.opsForValue().get(redisKey);
            RepeatWwGroupMerberQuery repeatWwGroupMerberQuery=new RepeatWwGroupMerberQuery();
            repeatWwGroupMerberQuery.setFalg(falg);
            repeatWwGroupMerberQuery.setMerId(deleRepeatMemberDto.getMerId());
            List<RepeatWwGroupMerberVo> repeatWwGroupMerberVoList = repeatWwGroupMerberMapper.getRepeatWwGroupMerber(repeatWwGroupMerberQuery);
            if(repeatWwGroupMerberVoList!=null&&!repeatWwGroupMerberVoList.isEmpty()){
                for (RepeatWwGroupMerberVo repeatWwGroupMerberVo:repeatWwGroupMerberVoList) {
                    try {
                        if(!StringUtils.isBlank(repeatWwGroupMerberVo.getGroupData())){
                            List<GroupData> groupDataList=JSONArray.parseArray(repeatWwGroupMerberVo.getGroupData(),GroupData.class);
                            if(groupDataList!=null&&!groupDataList.isEmpty()){
                                List<GroupData> groupDatas=keepOneGroupMember(groupDataList,repeatWwGroupMerberVo.getWxid(),repeatWwGroupMerberVo.getMerId(),deleRepeatMemberDto.getDeviceUniqueId());

                                if(groupDatas!=null&&groupDatas.stream().anyMatch(it->it.getStatus()==1)){
                                    repeatWwGroupMerberVo.setStatus(1);
                                }
                                repeatWwGroupMerberVo.setGroupData(JSONObject.toJSONString(groupDatas));

                                RepeatWwGroupMerber repeatWwGroupMerber=new RepeatWwGroupMerber();
                                BeanUtil.copyProperties(repeatWwGroupMerberVo,repeatWwGroupMerber);
                                repeatWwGroupMerberMapper.update(repeatWwGroupMerber);
                            }
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }

            }
        }

        //批量
        if(deleRepeatMemberDto.getKeepGroupDtoList()!=null&&!deleRepeatMemberDto.getKeepGroupDtoList().isEmpty()){

            for (KeepGroupDto keepGroupDto:deleRepeatMemberDto.getKeepGroupDtoList()) {
               RepeatWwGroupMerber repeatWwGroupMerber= repeatWwGroupMerberMapper.getById(keepGroupDto.getId(),deleRepeatMemberDto.getMerId());
               if(repeatWwGroupMerber!=null&&!StringUtils.isBlank(repeatWwGroupMerber.getGroupData())){

                   List<GroupData> groupDataList=JSONArray.parseArray(repeatWwGroupMerber.getGroupData(),GroupData.class);
                   if(groupDataList!=null&&!groupDataList.isEmpty()){
                       List<GroupData> groupDatas=keepOneGroupMember(groupDataList,repeatWwGroupMerber.getWxid(),repeatWwGroupMerber.getMerId(),deleRepeatMemberDto.getDeviceUniqueId());

                       if((groupDatas != null) && groupDatas.stream().anyMatch(it -> it.getStatus() == 1)) {
                           repeatWwGroupMerber.setStatus(1);
                       }
                       repeatWwGroupMerber.setGroupData(JSONObject.toJSONString(groupDatas));
                       repeatWwGroupMerberMapper.update(repeatWwGroupMerber);
                   }
               }
            }
        }
    }

    private List<GroupData> keepOneGroupMember(List<GroupData> groupDataList, String wxid, Long merId, Long deviceUniqueId) {
        Collections.shuffle(groupDataList,new Random(5));

        GroupData groupData=groupDataList.get(0);
        groupData.setStatus(0);

        List<String> removedIdList = new ArrayList<>();
        for (int i = 1; i < groupDataList.size(); i++) {
            GroupData group = groupDataList.get(i);
            group.setStatus(1);
            String groupWxid = group.getGroupWxid();
            removedIdList.add(groupWxid);
        }

        //删除群成员
        deleGroupMember(removedIdList,wxid,merId,deviceUniqueId);

        return groupDataList;
    }

    private void deleGroupMember(List<String> removedIdList, String wxid, Long merId, Long deviceUniqueId) {
        String delRepeatMemberNumber=String.format(RedisCacheKeyEnum.DEL_REPEAT_GROUP_MEMBER_NUMBER.getKey(),merId);

        if(removedIdList!=null&&!removedIdList.isEmpty()){
            for (String groupWxid:removedIdList) {
                WwGroupMember wwGroupMember = wwGroupMemberMapper.getByGroupWxIdAndWxid(groupWxid, wxid, merId);
                if(wwGroupMember!=null){
                    wwGroupMemberMapper.deleById(wwGroupMember.getId(),wwGroupMember.getMerId());
                    Integer num = (Integer) redisTemplate.opsForValue().get(delRepeatMemberNumber);
                    redisTemplate.opsForValue().set(delRepeatMemberNumber,num+1);


                    WwDevice wwDevice = wwDeviceMapper.getById(deviceUniqueId, merId);
                    //发送删除群成员指令
                    MicaTriggerGroupKickMsg micaTriggerGroupKickMsg = new MicaTriggerGroupKickMsg();
                    micaTriggerGroupKickMsg.setMessageId(wwGroupMember.getId());
                    micaTriggerGroupKickMsg.setGroupId(wwGroupMember.getGroupWxid());
                    micaTriggerGroupKickMsg.setWxIds(wwGroupMember.getWxid());

                    MicaTriggerDto micaTriggerDto = MicaTriggerDto.newInstance(micaTriggerGroupKickMsg, MicaTriggerType.TRIGGER_GROUP_KICK);
                    micaTriggerDto.setMerId(wwDevice.getMerId());
                    micaTriggerDto.setDeviceId(wwDevice.getDeviceId());
                    micaTriggerDto.setDeviceType(DeviceTypeEnum.DT_ANDROID_WORK_WECHAT_VALUE);
                    sendMsgProducer.pushMsg(micaTriggerDto, MicaTopics.WW_TRIGGER_TOPIC);
                }
            }
        }

    }
}
